from app.models.myUser import User
from fastapi import APIRouter
from app.common.resp import returnJson
from app.schemas.myUser import myUserIn
from app.common.returnExcept import UnicornException


user_api = APIRouter()

@user_api.get('/')
async def getAllUser():

    return returnJson(msg="OKOK", data="123")


@user_api.post("/")
async def addUser(userinfo: myUserIn):
    if userinfo.name == "123":
        raise UnicornException(name="名字错误")
    my = await User.create(username=userinfo.name, password=userinfo.password, mobile=userinfo.mobile, email=userinfo.email)
    print(my)

    return returnJson(data=my.__dict__)
